<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		.box{
			width: 100px;
			height: 100px;
			background: red url() 0 0 no-repeat;
			float: left;
			margin-right: 15px;
		}
	</style>
	<script>
		
		window.onload=function () {

			btn = document.getElementById('btn')
			box = document.getElementsByClassName('box')

			is = true;

			btn.onclick= function(){
				if(is){
					btn.innerHTML ="停止";
					time = setInterval(run,500)
					// time = setTimeout(run,5)
					is = false;
				}else{
					clearInterval(time)
					btn.innerHTML ="开始";
					is= true;
				}
			}

			color = ['green','red','yellow','blue','pink'];
			
			function run() {

				dd = color.pop();

				color.unshift(dd);

				for (var i = 0; i <box.length; i++) {
					box[i].style.background =color[i];
				}
				
			}
		}

	</script>
</head>
<body>
	<div class="box"></div>
	<div class="box"></div>
	<div class="box"></div>
	<div class="box"></div>
	<div class="box"></div>
	<button id="btn">开始</button>
</body>
</html>